#include "StdAfx.h"
#include "QQCardCmd.h"


QQCardCmd::QQCardCmd(void)
{
}


QQCardCmd::~QQCardCmd(void)
{
}

CString QQCardCmd::GetRandom()
{
	CString str;
	CString random;
	random.Format(_T("%d"),HYUnc::Random(10000000, 99999999));
	str = _T("0.") + random;
	random.Format(_T("%d"),HYUnc::Random(10000000, 99999999));
	str = str + random;
	return str;
}

CString QQCardCmd::Gtk(CMyDialog *dlg)
{
	CString skey;
	dlg->m_Cookies.Lookup(_T("skey"),skey);
	int hash = 5381;

	for(int i = 0;i<skey.GetLength();i++){
		hash += (hash << 5) + skey.GetAt(i);
	}

	return HYConv::Int2Str(hash & 0x7fffffff);
}

CString QQCardCmd::ResolveFunction(CStringArray &arr,const CString &function,int index)
{
	CString functionTemp = function;
	functionTemp.Trim();
	int pos = functionTemp.Find(_T("(")) + 1;
	int sum = functionTemp.GetLength() - pos - 2;
	CStringArray tempArr;
	HYCRegExp::Split(tempArr,',',functionTemp.Mid(pos,sum));
	for(int i = 0;i < tempArr.GetSize();i++){
		CString value = tempArr.GetAt(i);
		value.Trim();
		arr.Add(value.Mid(1,value.GetLength() - 2));
	}

	if(index > 0){
		return arr.GetAt(index - 1);
	} else {
		return _T("");
	}
}